home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / u16_pc.zip / XCODE.ASM < prev   
Assembly Source File  |  1993-01-06  |  25KB  |  988 lines

  1. ; xcode is the assembler optimized variable sized packed code
  2. ; extraction routines. Written by Tom Horsley
  3. ; (tahorsley@ssd.harris.com) Dec 1988.
  4. ;
  5. ; struct codebuf {
  6. ;    void near   (*codep)();
  7. ;    char near * bufp;
  8. ; };
  9. ;
  10. ; extern unsigned int near xcode(struct codebuf near * cbp)
  11. ;
  12. ; xcode extracts the next variable sized code from the buffer pointed
  13. ; at by bufp. The codep function pointer is a state variable recording
  14. ; the address of the routine that will be used to extract the next
  15. ; code byte.
  16. ;
  17. ; xcode works by jumping to the codep address. Each code extraction
  18. ; routine extracts the specific offset code it is designed for then
  19. ; sets codep to point to the next routine that will extract the next
  20. ; code. Eventually we sync up on a byte boundary and start over again
  21. ; with the original routine.
  22. ;
  23. ; Note: As you can see below, this uses the new .MODEL directive
  24. ; Microsoft introduced sometime around 5.0, so you need the latest
  25. ; version of the assembler to build this.
  26.  
  27. .MODEL     SMALL
  28. .CODE
  29.      PUBLIC       _xcode
  30. _xcode     PROC
  31.      push       bp
  32.      mov       bp,sp     ; add code to push ss, ds, si, di
  33.      push       si
  34.  
  35.      mov       bx,[bp+4] ; bx points to codebuf struct
  36.      mov       cx,[bx]   ; cx points to routine
  37.      mov       si,[bx+2] ; si points to data buffer
  38.      call       cx         ; go make state transition
  39.      mov       [bx],cx   ; save new state routine
  40.      mov       [bx+2],si ; save new buffer ptr
  41.  
  42.      pop       si
  43.      pop       bp         ; add code to pop di, si, ds, ss
  44.      ret
  45. _xcode     ENDP
  46.  
  47. ; The following code implements all the code extraction routines.
  48. ; Because of the way that the net compress utility works there are
  49. ; eight routines for each size code from 9 to 15 bits. For 10, 12, 14,
  50. ; and 16 bits we could do with fewer routines since we sync up on a
  51. ; byte boundary before looking at n_bits bytes, but the compress.c
  52. ; code always flushes out to n_bits byte boundary when changing code
  53. ; size, so there are 8 routines not just to extract codes, but also to
  54. ; maintain unique state information so that a buffer flush can get to
  55. ; the correct byte boundary to find the next set of codes.
  56. ;
  57. ; A fanatic would probably say "My gosh! we are wasteing space!" and
  58. ; implement a new magic number and a new compression algorithm to
  59. ; recover the dozen or so bytes wasted, but since I am not (that sort
  60. ; of) a fanatic, and I like the idea of sticking to standards, I leave
  61. ; it the way it is. (P.S. The percentage of wasted space is somewhere
  62. ; around .000001, so there is no real reason to get upset).
  63.  
  64. ; ********************************************** 9 bit code extraction routines
  65.  
  66.      PUBLIC       _init9
  67. _init9     PROC
  68.      push       bp
  69.      mov       bp,sp
  70.      mov       bx,[bp+4] ; bx points to codebuf struct
  71.      mov       cx,offset g9c0 ; initialize state to g9c0
  72.      mov       [bx],cx   ; save new state routine
  73.      pop       bp
  74.      ret
  75. _init9     ENDP
  76.  
  77. ; g9c0 get 9 bit code 0: 11111111 -------1
  78.  
  79. g9c0     PROC
  80.      mov       ax,[si]   ; get low in al, high bit in ah
  81.      and       ah,001h   ; mask off junk
  82.      inc       si         ; skip past first byte
  83.      mov       cx,offset g9c1 ; point to next code routine
  84.      ret
  85. g9c0     ENDP
  86.  
  87. ; g9c1 get 9 bit code 1: 1111111- ------11
  88.  
  89. g9c1     PROC
  90.      mov       ax,[si]   ; get data in ax << 1
  91.      shr       ax,1         ; position correctly
  92.      and       ah,001h   ; mask junk
  93.      inc       si         ; skip to next
  94.      mov       cx,offset g9c2 ; point to next code routine
  95.      ret
  96. g9c1     ENDP
  97.  
  98. ; g9c2 get 9 bit code 2: 111111-- -----111
  99.  
  100. g9c2     PROC
  101.      mov       ax,[si]   ; get data in ax << 2
  102.      shr       ax,1         ; position correctly
  103.      shr       ax,1
  104.      and       ah,001h   ; mask junk
  105.      inc       si         ; skip to next
  106.      mov       cx,offset g9c3 ; point to next code routine
  107.      ret
  108. g9c2     ENDP
  109.  
  110. ; g9c3 get 9 bit code 3: 11111--- ----1111
  111.  
  112. g9c3     PROC
  113.      mov       ax,[si]   ; get data in ax << 3
  114.      shr       ax,1         ; position correctly
  115.      shr       ax,1
  116.      shr       ax,1
  117.      and       ah,001h   ; mask junk
  118.      inc       si         ; skip to next
  119.      mov       cx,offset g9c4 ; point to next code routine
  120.      ret
  121. g9c3     ENDP
  122.  
  123. ; g9c4 get 9 bit code 4: 1111---- ---11111
  124.  
  125. g9c4     PROC
  126.      mov       ax,[si]   ; get data in ax << 4
  127.      shr       ax,1         ; position correctly
  128.      shr       ax,1
  129.      shr       ax,1
  130.      shr       ax,1
  131.      and       ah,001h   ; mask junk
  132.      inc       si         ; skip to next
  133.      mov       cx,offset g9c5 ; point to next code routine
  134.      ret
  135. g9c4     ENDP
  136.  
  137. ; g9c5 get 9 bit code 5: 111----- --111111
  138.  
  139. g9c5     PROC
  140.      mov       ax,[si]   ; ax = --123456 789-----
  141.      xchg       ah,al     ; ax = 789----- --123456
  142.      rol       ax,1         ; ax = 89------ -1234567
  143.      rol       ax,1         ; ax = 9------- 12345678
  144.      rol       ax,1         ; ax = -------1 23456789
  145.      and       ah,001h   ; mask junk
  146.      inc       si         ; skip to next
  147.      mov       cx,offset g9c6 ; point to next code routine
  148.      ret
  149. g9c5     ENDP
  150.  
  151. ; g9c6 get 9 bit code 6: 11------ -1111111
  152.  
  153. g9c6     PROC
  154.      mov       ax,[si]   ; ax = -1234567 89------
  155.      xchg       ah,al     ; ax = 89------ -1234567
  156.      rol       ax,1         ; ax = 9------- 12345678
  157.      rol       ax,1         ; ax = -------1 23456789
  158.      and       ah,001h   ; mask junk
  159.      inc       si         ; skip to next
  160.      mov       cx,offset g9c7 ; point to next code routine
  161.      ret
  162. g9c6     ENDP
  163.  
  164. ; g9c7 get 9 bit code 7: 1------- 11111111
  165.  
  166. g9c7     PROC
  167.      mov       ax,[si]   ; ax = 12345678 9-------
  168.      xchg       ah,al     ; ax = 9------- 12345678
  169.      rol       ax,1         ; ax = -------1 23456789
  170.      and       ah,001h   ; mask junk
  171.      inc       si         ; skip to next
  172.      inc       si         ; skip to next
  173.      mov       cx,offset g9c0 ; synced, point back to code 0 routine
  174.      ret
  175. g9c7     ENDP
  176.  
  177. ; ********************************************* 10 bit code extraction routines
  178.  
  179.      PUBLIC       _init10
  180. _init10     PROC
  181.      push       bp
  182.      mov       bp,sp
  183.      mov       bx,[bp+4] ; bx points to codebuf struct
  184.      mov       cx,offset g10c0 ; initialize state to g10c0
  185.      mov       [bx],cx   ; save new state routine
  186.      pop       bp
  187.      ret
  188. _init10     ENDP
  189.  
  190. ; g10c0 get 10 bit code 0: 11111111 ------11
  191.  
  192. g10c0     PROC
  193.      mov       ax,[si]   ; code in ax
  194.      and       ah,003h   ; mask off junk
  195.      inc       si         ; point to next byte
  196.      mov       cx,offset g10c1 ; point to next code routine
  197.      ret
  198. g10c0     ENDP
  199.  
  200. ; g10c1 get 10 bit code 1: 111111-- ----1111
  201.  
  202. g10c1     PROC
  203.      mov       ax,[si]   ; ax = ----1234 56789a--
  204.      shr       ax,1         ; ax = -----123 456789a-
  205.      shr       ax,1         ; ax = ------12 3456789a
  206.      and       ah,003h   ; mask off junk
  207.      inc       si         ; point to next byte
  208.      mov       cx,offset g10c2 ; point to next code routine
  209.      ret
  210. g10c1     ENDP
  211.  
  212. ; g10c2 get 10 bit code 2: 1111---- --111111
  213.  
  214. g10c2     PROC
  215.      mov       ax,[si]   ; ax = --123456 789a----
  216.      shr       ax,1         ; ax = ---12345 6789a---
  217.      shr       ax,1         ; ax = ----1234 56789a--
  218.      shr       ax,1         ; ax = -----123 456789a-
  219.      shr       ax,1         ; ax = ------12 3456789a
  220.      and       ah,003h   ; mask off junk
  221.      inc       si         ; point to next byte
  222.      mov       cx,offset g10c3 ; point to next code routine
  223.      ret
  224. g10c2     ENDP
  225.  
  226. ; g10c3 get 10 bit code 3: 11------ 11111111
  227.  
  228. g10c3     PROC
  229.      mov       ax,[si]   ; ax = 12345678 9a------
  230.      xchg       ah,al     ; ax = 9a------ 12345678
  231.      rol       ax,1         ; ax = a------1 23456789
  232.      rol       ax,1         ; ax = ------12 3456789a
  233.      and       ah,003h   ; mask off junk
  234.      inc       si         ; inc past code
  235.      inc       si
  236.      mov       cx,offset g10c4 ; point to next code routine
  237.      ret
  238. g10c3     ENDP
  239.  
  240. ; g10c4 get 10 bit code 4: 11111111 ------11
  241.  
  242. g10c4     PROC             ; same as c0
  243.      mov       ax,[si]
  244.      and       ah,003h
  245.      inc       si
  246.      mov       cx,offset g10c5
  247.      ret
  248. g10c4     ENDP
  249.  
  250. ; g10c5 get 10 bit code 5: 111111-- ----1111
  251.  
  252. g10c5     PROC             ; same as c1
  253.      mov       ax,[si]
  254.      shr       ax,1
  255.      shr       ax,1
  256.      and       ah,003h
  257.      inc       si
  258.      mov       cx,offset g10c6
  259.      ret
  260. g10c5     ENDP
  261.  
  262. ; g10c6 get 10 bit code 6: 1111---- --111111
  263.  
  264. g10c6     PROC             ; same as c2
  265.      mov       ax,[si]
  266.      shr       ax,1
  267.      shr       ax,1
  268.      shr       ax,1
  269.      shr       ax,1
  270.      and       ah,003h
  271.      inc       si
  272.      mov       cx,offset g10c7
  273.      ret
  274. g10c6     ENDP
  275.  
  276. ; g10c7 get 10 bit code 3: 11------ 11111111
  277.  
  278. g10c7     PROC             ; same as c3
  279.      mov       ax,[si]
  280.      xchg       ah,al
  281.      rol       ax,1
  282.      rol       ax,1
  283.      and       ah,003h
  284.      inc       si
  285.      inc       si
  286.      mov       cx,offset g10c0 ; synced, wrap back around
  287.      ret
  288. g10c7     ENDP
  289.  
  290. ; ********************************************* 11 bit code extraction routines
  291.  
  292.      PUBLIC       _init11
  293. _init11     PROC
  294.      push       bp
  295.      mov       bp,sp
  296.      mov       bx,[bp+4] ; bx points to codebuf struct
  297.      mov       cx,offset g11c0 ; initialize state to g11c0
  298.      mov       [bx],cx   ; save new state routine
  299.      pop       bp
  300.      ret
  301. _init11     ENDP
  302.  
  303. ; g11c0 get 11 bit code 0: 11111111 -----111
  304.  
  305. g11c0     PROC
  306.      mov       ax,[si]   ; code in ax
  307.      and       ah,007h   ; mask off junk
  308.      inc       si         ; bump pointer
  309.      mov       cx,offset g11c1 ; point to next code routine
  310.      ret
  311. g11c0     ENDP
  312.  
  313. ; g11c1 get 11 bit code 1: 11111--- --111111
  314.  
  315. g11c1     PROC
  316.      mov       ax,[si]   ; ax = --123456 789ab---
  317.      shr       ax,1         ; ax = ---12345 6789ab--
  318.      shr       ax,1         ; ax = ----1234 56789ab-
  319.      shr       ax,1         ; ax = -----123 456789ab
  320.      and       ah,007h   ; mask off junk
  321.      inc       si         ; bump pointer
  322.      mov       cx,offset g11c2 ; point to next code routine
  323.      ret
  324. g11c1     ENDP
  325.  
  326. ; g11c2 get 11 bit code 2: 11------ 11111111 -------1
  327.  
  328. g11c2     PROC
  329.      mov       ax,[si]   ; ax = 23456789 ab------
  330.      inc       si         ; bump pointer
  331.      inc       si
  332.      mov       cl,[si]   ; cl = -------1
  333.      rcr       cl,1         ; carry bit = 1
  334.      rcr       ax,1         ; ax = 12345678 9ab-----
  335.      xchg       ah,al     ; ax = 9ab----- 12345678
  336.      rol       ax,1         ; ax = ab-----1 23456789
  337.      rol       ax,1         ; ax = b-----12 3456789a
  338.      rol       ax,1         ; ax = -----123 456789ab
  339.      and       ah,007h   ; mask off junk
  340.      mov       cx,offset g11c3 ; point to next code routine
  341.      ret
  342. g11c2     ENDP
  343.  
  344. ; g11c3 get 11 bit code 3: 1111111- ----1111
  345.  
  346. g11c3     PROC
  347.      mov       ax,[si]   ; ax = ----1234 56789ab-
  348.      shr       ax,1         ; ax = -----123 456789ab
  349.      and       ah,007h   ; mask off junk
  350.      inc       si         ; next byte
  351.      mov       cx,offset g11c4 ; point to next code routine
  352.      ret
  353. g11c3     ENDP
  354.  
  355. ; g11c4 get 11 bit code 4: 1111---- -1111111
  356.  
  357. g11c4     PROC
  358.      mov       ax,[si]   ; ax = -1234567 89ab----
  359.      shr       ax,1         ; ax = --123456 789ab---
  360.      shr       ax,1         ; ax = ---12345 6789ab--
  361.      shr       ax,1         ; ax = ----1234 56789ab-
  362.      shr       ax,1         ; ax = -----123 456789ab
  363.      and       ah,007h   ; mask off junk
  364.      inc       si         ; next byte
  365.      mov       cx,offset g11c5 ; point to next code routine
  366.      ret
  367. g11c4     ENDP
  368.  
  369. ; g11c5 get 11 bit code 5: 1------- 11111111 ------11
  370.  
  371. g11c5     PROC
  372.      mov       ax,[si]   ; ax = 3456789a b-------
  373.      and       al,080h   ; mask off junk
  374.      inc       si         ; bump pointer
  375.      inc       si
  376.      mov       cl,[si]   ; cl = ------12
  377.      and       cl,003h   ; mask off junk
  378.      or       al,cl     ; ax = 3456789a b-----12
  379.      rol       ax,1         ; ax = 456789ab -----123
  380.      xchg       ah,al     ; ax = -----123 456789ab
  381.      mov       cx,offset g11c6 ; point to next code routine
  382.      ret
  383. g11c5     ENDP
  384.  
  385. ; g11c6 get 11 bit code 6: 111111-- ---11111
  386.  
  387. g11c6     PROC
  388.      mov       ax,[si]   ; ax = ---12345 6789ab--
  389.      shr       ax,1         ; ax = ----1234 56789ab-
  390.      shr       ax,1         ; ax = -----123 456789ab
  391.      and       ah,007h   ; mask off junk
  392.      inc       si         ; bump pointer
  393.      mov       cx,offset g11c7 ; point to next code routine
  394.      ret
  395. g11c6     ENDP
  396.  
  397. ; g11c7 get 11 bit code 7: 111----- 11111111
  398.  
  399. g11c7     PROC
  400.      mov       ax,[si]   ; ax = 12345678 9ab-----
  401.      xchg       ah,al     ; ax = 9ab----- 12345678
  402.      rol       ax,1         ; ax = ab-----1 23456789
  403.      rol       ax,1         ; ax = b-----12 3456789a
  404.      rol       ax,1         ; ax = -----123 456789ab
  405.      and       ah,007h   ; mask off junk
  406.      inc       si         ; bump pointer
  407.      inc       si
  408.      mov       cx,offset g11c0 ; synced, wrap around
  409.      ret
  410. g11c7     ENDP
  411.  
  412. ; ********************************************* 12 bit code extraction routines
  413.  
  414.      PUBLIC       _init12
  415. _init12     PROC
  416.      push       bp
  417.      mov       bp,sp
  418.      mov       bx,[bp+4] ; bx points to codebuf struct
  419.      mov       cx,offset g12c0 ; initialize state to g12c0
  420.      mov       [bx],cx   ; save new state routine
  421.      pop       bp
  422.      ret
  423. _init12     ENDP
  424.  
  425. ; g12c0 get 12 bit code 0: 11111111 ----1111
  426.  
  427. g12c0     PROC
  428.      mov       ax,[si]   ; code in ax
  429.      and       ah,00fh   ; mask off junk
  430.      inc       si         ; next byte
  431.      mov       cx,offset g12c1 ; point to next routine
  432.      ret
  433. g12c0     ENDP
  434.  
  435. ; g12c1 get 12 bit code 1: 1111---- 11111111
  436.  
  437. g12c1     PROC
  438.      mov       ax,[si]   ; ax = 12345678 9abc----
  439.      shr       ax,1         ; ax = -1234567 89abc---
  440.      shr       ax,1         ; ax = --123456 789abc--
  441.      shr       ax,1         ; ax = ---12345 6789abc-
  442.      shr       ax,1         ; ax = ----1234 56789abc
  443.      inc       si         ; bump pointer
  444.      inc       si
  445.      mov       cx,offset g12c2 ; point to next routine
  446.      ret
  447. g12c1     ENDP
  448.  
  449. ; g12c2 get 12 bit code 2: 11111111 ----1111
  450.  
  451. g12c2     PROC             ; same as 0
  452.      mov       ax,[si]
  453.      and       ah,00fh
  454.      inc       si
  455.      mov       cx,offset g12c3
  456.      ret
  457. g12c2     ENDP
  458.  
  459. ; g12c3 get 12 bit code 3: 1111---- 11111111
  460.  
  461. g12c3     PROC             ; same as 1
  462.      mov       ax,[si]
  463.      shr       ax,1
  464.      shr       ax,1
  465.      shr       ax,1
  466.      shr       ax,1
  467.      inc       si
  468.      inc       si
  469.      mov       cx,offset g12c4
  470.      ret
  471. g12c3     ENDP
  472.  
  473. ; g12c4 get 12 bit code 4: 11111111 ----1111
  474.  
  475. g12c4     PROC             ; same as 0
  476.      mov       ax,[si]
  477.      and       ah,00fh
  478.      inc       si
  479.      mov       cx,offset g12c5
  480.      ret
  481. g12c4     ENDP
  482.  
  483. ; g12c5 get 12 bit code 5: 1111---- 11111111
  484.  
  485. g12c5     PROC             ; same as 1
  486.      mov       ax,[si]
  487.      shr       ax,1
  488.      shr       ax,1
  489.      shr       ax,1
  490.      shr       ax,1
  491.      inc       si
  492.      inc       si
  493.      mov       cx,offset g12c6
  494.      ret
  495. g12c5     ENDP
  496.  
  497. ; g12c6 get 12 bit code 6: 11111111 ----1111
  498.  
  499. g12c6     PROC             ; same as 0
  500.      mov       ax,[si]
  501.      and       ah,00fh
  502.      inc       si
  503.      mov       cx,offset g12c7
  504.      ret
  505. g12c6     ENDP
  506.  
  507. ; g12c7 get 12 bit code 7: 1111---- 11111111
  508.  
  509. g12c7     PROC             ; same as 1
  510.      mov       ax,[si]
  511.      shr       ax,1
  512.      shr       ax,1
  513.      shr       ax,1
  514.      shr       ax,1
  515.      inc       si
  516.      inc       si
  517.      mov       cx,offset g12c0 ; synced, wrap around
  518.      ret
  519. g12c7     ENDP
  520.  
  521. ; ********************************************* 13 bit code extraction routines
  522.  
  523.      PUBLIC       _init13
  524. _init13     PROC
  525.      push       bp
  526.      mov       bp,sp
  527.      mov       bx,[bp+4] ; bx points to codebuf struct
  528.      mov       cx,offset g13c0 ; initialize state to g13c0
  529.      mov       [bx],cx   ; save new state routine
  530.      pop       bp
  531.      ret
  532. _init13     ENDP
  533.  
  534. ; g13c0 get 13 bit code 0: 11111111 ---11111
  535.  
  536. g13c0     PROC
  537.      mov       ax,[si]   ; ax = 12345 6789abcd
  538.      and       ah,01fh   ; mask off junk
  539.      inc       si         ; bump pointer
  540.      mov       cx,offset g13c1 ; point to next routine
  541.      ret
  542. g13c0     ENDP
  543.  
  544. ; g13c1 get 13 bit code 1: 111----- 11111111 ------11
  545.  
  546. g13c1     PROC
  547.      mov       ax,[si]   ; ax = 3456789a bcd-----
  548.      and       al,0e0h   ; mask off junk
  549.      inc       si         ; bump pointer
  550.      inc       si
  551.      mov       cl,[si]   ; cl = ------12
  552.      and       cl,003h   ; mask off junk
  553.      or       al,cl     ; ax = 3456789a bcd---12
  554.      rol       ax,1         ; ax = 456789ab cd---123
  555.      rol       ax,1         ; ax = 56789abc d---1234
  556.      rol       ax,1         ; ax = 6789abcd ---12345
  557.      xchg       ah,al     ; ax = ---12345 6789abcd
  558.      mov       cx,offset g13c2 ; point to next routine
  559.      ret
  560. g13c1     ENDP
  561.  
  562. ; g13c2 get 13 bit code 2: 111111-- -1111111
  563.  
  564. g13c2     PROC
  565.      mov       ax,[si]   ; ax = -1234567 89abcd--
  566.      shr       ax,1         ; ax = --123456 789abcd-
  567.      shr       ax,1         ; ax = ---12345 6789abcd
  568.      and       ah,01fh   ; mask junk
  569.      inc       si         ; bump pointer
  570.      mov       cx,offset g13c3 ; point to next routine
  571.      ret
  572. g13c2     ENDP
  573.  
  574. ; g13c3 get 13 bit code 3: 1------- 11111111 ----1111
  575.  
  576. g13c3     PROC
  577.      mov       ax,[si]   ; ax = 56789abc d-------
  578.      inc       si         ; bump pointer
  579.      inc       si
  580.      mov       cl,[si]   ; cl = ----1234
  581.      and       cl,00fh   ; mask junk
  582.      and       al,080h   ; mask junk
  583.      or       al,cl     ; ax = 56789abc d---1234
  584.      rol       ax,1         ; ax = 6789abcd ---12345
  585.      xchg       ah,al     ; ax = ---12345 6789abcd
  586.      mov       cx,offset g13c4 ; point to next routine
  587.      ret
  588. g13c3     ENDP
  589.  
  590. ; g13c4 get 13 bit code 4: 1111---- 11111111 -------1
  591.  
  592. g13c4     PROC
  593.      mov       ax,[si]   ; ax = 23456789 abcd----
  594.      inc       si         ; bump pointer
  595.      inc       si
  596.      mov       cl,[si]   ; cl = ------1
  597.      rcr       cl,1         ; carry bit = 1
  598.      rcr       ax,1         ; ax = 12345678 9abcd---
  599.      shr       ax,1         ; ax = -1234567 89abcd--
  600.      shr       ax,1         ; ax = --123456 789abcd-
  601.      shr       ax,1         ; ax = ---12345 6789abcd
  602.      mov       cx,offset g13c5 ; point to next routine
  603.      ret
  604. g13c4     ENDP
  605.  
  606. ; g13c5 get 13 bit code 5: 1111111- --111111
  607.  
  608. g13c5     PROC
  609.      mov       ax,[si]   ; ax = --123456 789abcd-
  610.      shr       ax,1         ; ax = ---12345 6789abcd
  611.      and       ah,01fh   ; mask junk
  612.      inc       si
  613.      mov       cx,offset g13c6 ; point to next routine
  614.      ret
  615. g13c5     ENDP
  616.  
  617. ; g13c6 get 13 bit code 6: 11------ 11111111 -----111
  618.  
  619. g13c6     PROC
  620.      mov       ax,[si]   ; ax = 456789ab cd------
  621.      inc       si
  622.      inc       si
  623.      mov       cl,[si]   ; cl = -----123
  624.      and       al,0c0h   ; mask junk
  625.      and       cl,007h   ; mask junk
  626.      or       al,cl     ; ax = 456789ab cd---123
  627.      rol       ax,1         ; ax = 56789abc d---1234
  628.      rol       ax,1         ; ax = 6789abcd ---12345
  629.      xchg       ah,al     ; ax = ---12345 6789abcd
  630.      mov       cx,offset g13c7 ; point to next routine
  631.      ret
  632. g13c6     ENDP
  633.  
  634. ; g13c7 get 13 bit code 7: 11111--- 11111111
  635.  
  636. g13c7     PROC
  637.      mov       ax,[si]   ; ax = 12345678 9abcd---
  638.      shr       ax,1         ; ax = -1234567 89abcd--
  639.      shr       ax,1         ; ax = --123456 789abcd-
  640.      shr       ax,1         ; ax = ---12345 6789abcd
  641.      inc       si         ; bump pointer
  642.      inc       si
  643.      mov       cx,offset g13c0 ; synced, wrap around
  644.      ret
  645. g13c7     ENDP
  646.  
  647. ; ********************************************* 14 bit code extraction routines
  648.  
  649.      PUBLIC       _init14
  650. _init14     PROC
  651.      push       bp
  652.      mov       bp,sp
  653.      mov       bx,[bp+4] ; bx points to codebuf struct
  654.      mov       cx,offset g14c0 ; initialize state to g14c0
  655.      mov       [bx],cx   ; save new state routine
  656.      pop       bp
  657.      ret
  658. _init14     ENDP
  659.  
  660. ; g14c0 get 14 bit code 0: 11111111 --111111
  661.  
  662. g14c0     PROC
  663.      mov       ax,[si]   ; ax = --123456 789abcde
  664.      and       ah,03fh   ; mask junk
  665.      inc       si         ; bump pointer
  666.      mov       cx,offset g14c1 ; point to next routine
  667.      ret
  668. g14c0     ENDP
  669.  
  670. ; g14c1 get 14 bit code 1: 11------ 11111111 ----1111
  671.  
  672. g14c1     PROC
  673.      mov       ax,[si]   ; ax = 56789abc de------
  674.      inc       si
  675.      inc       si
  676.      mov       cl,[si]   ; cl = ----1234
  677.      and       al,0c0h   ; mask junk
  678.      and       cl,00fh   ; mask junk
  679.      or       al,cl     ; ax = 56789abc de--1234
  680.      rol       ax,1         ; ax = 6789abcd e--12345
  681.      rol       ax,1         ; ax = 789abcde --123456
  682.      xchg       ah,al     ; ax = --123456 789abcde
  683.      mov       cx,offset g14c2 ; point to next routine
  684.      ret
  685. g14c1     ENDP
  686.  
  687. ; g14c2 get 14 bit code 2: 1111---- 11111111 ------11
  688.  
  689. g14c2     PROC
  690.      mov       ax,[si]   ; ax = 3456789a bcde----
  691.      inc       si
  692.      inc       si
  693.      mov       cl,[si]   ; cl = ------12
  694.      and       al,0f0h   ; mask junk
  695.      and       cl,003h   ; mask junk
  696.      or       al,cl     ; ax = 3456789a bcde--12
  697.      ror       ax,1         ; ax = 23456789 abcde--1
  698.      ror       ax,1         ; ax = 12345678 9abcde--
  699.      shr       ax,1         ; ax = -1234567 89abcde-
  700.      shr       ax,1         ; ax = --123456 789abcde
  701.      mov       cx,offset g14c3 ; point to next routine
  702.      ret
  703. g14c2     ENDP
  704.  
  705. ; g14c3 get 14 bit code 3: 111111-- 11111111
  706.  
  707. g14c3     PROC
  708.      mov       ax,[si]   ; ax = 12345678 9abcde--
  709.      shr       ax,1         ; ax = -1234567 89abcde-
  710.      shr       ax,1         ; ax = --123456 789abcde
  711.      inc       si
  712.      inc       si
  713.      mov       cx,offset g14c4 ; point to next routine
  714.      ret
  715. g14c3     ENDP
  716.  
  717. ; g14c4 get 14 bit code 4: 11111111 --111111
  718.  
  719. g14c4     PROC             ; same as 0
  720.      mov       ax,[si]
  721.      and       ah,03fh
  722.      inc       si
  723.      mov       cx,offset g14c5
  724.      ret
  725. g14c4     ENDP
  726.  
  727. ; g14c5 get 14 bit code 5: 11------ 11111111 ----1111
  728.  
  729. g14c5     PROC             ; same as 1
  730.      mov       ax,[si]
  731.      inc       si
  732.      inc       si
  733.      mov       cl,[si]
  734.      and       al,0c0h
  735.      and       cl,00fh
  736.      or       al,cl
  737.      rol       ax,1
  738.      rol       ax,1
  739.      xchg       ah,al
  740.      mov       cx,offset g14c6
  741.      ret
  742. g14c5     ENDP
  743.  
  744. ; g14c6 get 14 bit code 6: 1111---- 11111111 ------11
  745.  
  746. g14c6     PROC             ; same as 2
  747.      mov       ax,[si]
  748.      inc       si
  749.      inc       si
  750.      mov       cl,[si]
  751.      and       al,0f0h
  752.      and       cl,003h
  753.      or       al,cl
  754.      ror       ax,1
  755.      ror       ax,1
  756.      shr       ax,1
  757.      shr       ax,1
  758.      mov       cx,offset g14c7
  759.      ret
  760. g14c6     ENDP
  761.  
  762. ; g14c7 get 14 bit code 7: 111111-- 11111111
  763.  
  764. g14c7     PROC             ; same as 3
  765.      mov       ax,[si]
  766.      shr       ax,1
  767.      shr       ax,1
  768.      inc       si
  769.      inc       si
  770.      mov       cx,offset g14c0 ; synced, wrap around
  771.      ret
  772. g14c7     ENDP
  773.  
  774. ; ********************************************* 15 bit code extraction routines
  775.  
  776.      PUBLIC       _init15
  777. _init15     PROC
  778.      push       bp
  779.      mov       bp,sp
  780.      mov       bx,[bp+4] ; bx points to codebuf struct
  781.      mov       cx,offset g15c0 ; initialize state to g15c0
  782.      mov       [bx],cx   ; save new state routine
  783.      pop       bp
  784.      ret
  785. _init15     ENDP
  786.  
  787. ; g15c0 get 15 bit code 0: 11111111 -1111111
  788.  
  789. g15c0     PROC
  790.      mov       ax,[si]   ; ax = -1234567 89abcdef
  791.      and       ah,07fh   ; mask junk
  792.      inc       si
  793.      mov       cx,offset g15c1 ; point to next routine
  794.      ret
  795. g15c0     ENDP
  796.  
  797. ; g15c1 get 15 bit code 1: 1------- 11111111 --111111
  798.  
  799. g15c1     PROC
  800.      mov       ax,[si]   ; ax = 789abcde f-------
  801.      inc       si
  802.      inc       si
  803.      mov       cl,[si]   ; ax = --123456
  804.      and       al,080h   ; mask junk
  805.      and       cl,03fh   ; mask junk
  806.      or       al,cl     ; ax = 789abcde f-123456
  807.      rol       ax,1         ; ax = 89abcdef -1234567
  808.      xchg       ah,al     ; ax = -1234567 89abcdef
  809.      mov       cx,offset g15c2 ; point to next routine
  810.      ret
  811. g15c1     ENDP
  812.  
  813. ; g15c2 get 15 bit code 2: 11------ 11111111 ---11111
  814.  
  815. g15c2     PROC
  816.      mov       ax,[si]   ; ax = 6789abcd ef------
  817.      inc       si
  818.      inc       si
  819.      mov       cl,[si]   ; cl = ---12345
  820.      and       al,0c0h   ; mask junk
  821.      and       cl,01fh   ; mask junk
  822.      or       al,cl     ; ax = 6789abcd ef-12345
  823.      rol       ax,1         ; ax = 789abcde f-123456
  824.      rol       ax,1         ; ax = 89abcdef -1234567
  825.      xchg       ah,al     ; ax = -1234567 89abcdef
  826.      mov       cx,offset g15c3 ; point to next routine
  827.      ret
  828. g15c2     ENDP
  829.  
  830. ; g15c3 get 15 bit code 3: 111----- 11111111 ----1111
  831.  
  832. g15c3     PROC
  833.      mov       ax,[si]   ; ax = 56789abc def-----
  834.      inc       si
  835.      inc       si
  836.      mov       cl,[si]   ; cl = ----1234
  837.      and       al,0e0h
  838.      and       cl,00fh
  839.      or       al,cl     ; ax = 56789abc def-1234
  840.      rol       ax,1         ; ax = 6789abcd ef-12345
  841.      rol       ax,1         ; ax = 789abcde f-123456
  842.      rol       ax,1         ; ax = 89abcdef -1234567
  843.      xchg       ah,al     ; ax = -1234567 89abcdef
  844.      mov       cx,offset g15c4 ; point to next routine
  845.      ret
  846. g15c3     ENDP
  847.  
  848. ; g15c4 get 15 bit code 4: 1111---- 11111111 -----111
  849.  
  850. g15c4     PROC
  851.      mov       ax,[si]   ; ax = 456789ab cdef----
  852.      inc       si
  853.      inc       si
  854.      mov       cl,[si]   ; cl = -----123
  855.      and       cl,007h
  856.      and       al,0f0h
  857.      or       al,cl     ; ax = 456789ab cdef-123
  858.      ror       ax,1         ; ax = 3456789a bcdef-12
  859.      ror       ax,1         ; ax = 23456789 abcdef-1
  860.      ror       ax,1         ; ax = 12345678 9abcdef-
  861.      shr       ax,1         ; ax = -1234567 89abcdef
  862.      mov       cx,offset g15c5 ; point to next routine
  863.      ret
  864. g15c4     ENDP
  865.  
  866. ; g15c5 get 15 bit code 5: 11111--- 11111111 ------11
  867.  
  868. g15c5     PROC
  869.      mov       ax,[si]   ; ax = 3456789a bcdef---
  870.      inc       si
  871.      inc       si
  872.      mov       cl,[si]   ; cl = ------12
  873.      and       al,0f8h
  874.      and       cl,003h
  875.      or       al,cl     ; ax = 3456789a bcdef-12
  876.      ror       ax,1         ; ax = 23456789 abcdef-1
  877.      ror       ax,1         ; ax = 12345678 9abcdef-
  878.      shr       ax,1         ; ax = -1234567 89abcdef
  879.      mov       cx,offset g15c6 ; point to next routine
  880.      ret
  881. g15c5     ENDP
  882.  
  883. ; g15c6 get 15 bit code 6: 111111-- 11111111 -------1
  884.  
  885. g15c6     PROC
  886.      mov       ax,[si]   ; ax = 23456789 abcdef--
  887.      inc       si
  888.      inc       si
  889.      mov       cl,[si]   ; cl = -------1
  890.      rcr       cl,1         ; carry bit = 1
  891.      rcr       ax,1         ; ax = 12345678 9abcdef-
  892.      shr       ax,1         ; ax = -1234567 89abcdef
  893.      mov       cx,offset g15c7 ; point to next routine
  894.      ret
  895. g15c6     ENDP
  896.  
  897. ; g15c7 get 15 bit code 7: 1111111- 11111111
  898.  
  899. g15c7     PROC
  900.      mov       ax,[si]   ; ax = 12345678 9abcdef-
  901.      shr       ax,1         ; ax = -1234567 89abcdef
  902.      inc       si
  903.      inc       si
  904.      mov       cx,offset g15c0 ; synced, wrap around
  905.      ret
  906. g15c7     ENDP
  907.  
  908. ; ********************************************** 16 bit code extraction routine
  909.  
  910.      PUBLIC       _init16
  911. _init16     PROC
  912.      push       bp
  913.      mov       bp,sp
  914.      mov       bx,[bp+4] ; bx points to codebuf struct
  915.      mov       cx,offset g16c0 ; initialize state to g16c0
  916.      mov       [bx],cx   ; save new state routine
  917.      pop       bp
  918.      ret
  919. _init16     ENDP
  920.  
  921. ; g16c0 get 16 bit code 0: 11111111 11111111
  922.  
  923. g16c0     PROC
  924.      mov       ax,[si]   ; get low & high bytes
  925.      inc       si         ; skip past them
  926.      inc       si
  927.      mov       cx,offset g16c1 ; next routine
  928.      ret
  929. g16c0     ENDP
  930.  
  931. g16c1     PROC             ; same as 0
  932.      mov       ax,[si]
  933.      inc       si
  934.      inc       si
  935.      mov       cx,offset g16c2
  936.      ret
  937. g16c1     ENDP
  938.  
  939. g16c2     PROC             ; same as 0
  940.      mov       ax,[si]
  941.      inc       si
  942.      inc       si
  943.      mov       cx,offset g16c3
  944.      ret
  945. g16c2     ENDP
  946.  
  947. g16c3     PROC             ; same as 0
  948.      mov       ax,[si]
  949.      inc       si
  950.      inc       si
  951.      mov       cx,offset g16c4
  952.      ret
  953. g16c3     ENDP
  954.  
  955. g16c4     PROC             ; same as 0
  956.      mov       ax,[si]
  957.      inc       si
  958.      inc       si
  959.      mov       cx,offset g16c5
  960.      ret
  961. g16c4     ENDP
  962.  
  963. g16c5     PROC             ; same as 0
  964.      mov       ax,[si]
  965.      inc       si
  966.      inc       si
  967.      mov       cx,offset g16c6
  968.      ret
  969. g16c5     ENDP
  970.  
  971. g16c6     PROC             ; same as 0
  972.      mov       ax,[si]
  973.      inc       si
  974.      inc       si
  975.      mov       cx,offset g16c7
  976.      ret
  977. g16c6     ENDP
  978.  
  979. g16c7     PROC             ; same as 0
  980.      mov       ax,[si]
  981.      inc       si
  982.      inc       si
  983.      mov       cx,offset g16c0 ; wrap back around
  984.      ret
  985. g16c7     ENDP
  986.  
  987.      END
  988.